import 'package:flutter/material.dart';
import 'package:xview/routers/index.dart';
import 'package:xview/utils/dimension.dart';

class xNavbarTwo extends StatefulWidget implements PreferredSizeWidget {
  Color color;
  String title;
  Color titleColor;
  num titleSize;
  FontWeight titleFontWeight;
  IconData leftIcon;
  Color leftIconColor;
  double leftIconSize;
  Function? customBack; //自定义返回逻辑
  bool centerTitle;
  double elevation; //阴影大小

  xNavbarTwo({
    this.color = Colors.white,
    required this.title,
    this.titleColor = const Color(0xFF1F2329),
    this.titleSize = 17,
    this.titleFontWeight = FontWeight.bold,
    this.leftIcon = Icons.arrow_back_ios,
    this.leftIconColor = const Color.fromRGBO(31, 35, 41, 1),
    this.leftIconSize = 24,
    this.centerTitle = true,
    this.elevation = 0,
    this.customBack,
  });

  @override
  State<StatefulWidget> createState() {
    return _xNavbarState();
  }

  @override
  // TODO: implement preferredSize
  Size get preferredSize => new Size(100.0, 50.0);
}

class _xNavbarState extends State<xNavbarTwo> {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      title: Text("${widget.title}",style: TextStyle(color: widget.titleColor,fontSize: Dimension(context).toPx(widget.titleSize),fontWeight: widget.titleFontWeight)),
      leading: GestureDetector(
        onTap: (){
          print(widget.customBack);
          MyRouter.back(context);
        },
        child: Icon(widget.leftIcon,color: widget.leftIconColor,size: widget.leftIconSize),
      ),
      centerTitle: widget.centerTitle,
      backgroundColor: widget.color,
      elevation: widget.elevation,
    );
  }
}
